#include <iostream>
#include <map>

using namespace std;

int main()
{
	map<int, double, greater<int>> mp;

	int K, key;
	double value;

	for (int i = 0; i < 2; i++)
	{
		cin >> K;
		for (int j = 0; j < K; j++)
		{
			cin >> key >> value;
			if (mp.count(key) != 0)
			{
				mp[key] += value;
			}
			else
			{
				// mp.insert(make_pair(key, value));
				mp[key] = value;
			}
		}
	}

	for (map<int, double>::iterator m = mp.begin(); m != mp.end(); m++)
	{
		if (m->second == 0)
		{
			mp.erase(m);
		}
	}

	if(mp.empty())
	{
		// cout << "empty!" << endl;
		cout << 0;
	}
	else
	{
		cout << mp.size();
		for (map<int, double>::iterator m = mp.begin(); m != mp.end(); m++)
		{
			printf(" %d %.1f", m->first, m->second);
		}
	}

	return 0;
}
